<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增课程</title>
    <script src="/js/jquery-1.7.2.js"></script>
</head>
<body>
<h1>新增课程</h1>
<p>课程名称: <input type="text" name="courseName" placeholder="课程名称"></p>
<p>授课教师: <input type="text" name="teacherName" placeholder="授课教师"></p>
<p>教室容量: <input type="text" name="croomCapacity" placeholder="教室容量"></p>
<p>
    <button id="add_btn">确认添加</button>
</p>
<script>
    $(function () {
        $("#add_btn").click(function () {
            let course = {};
            course.courseName = $("input[name='courseName']").val();
            course.teacherName = $("input[name='teacherName']").val();
            course.croomCapacity = $("input[name='croomCapacity']").val();
            $.ajax({
                type: "POST",
                url: "/course/addcourse",
                data: JSON.stringify(course),
                contentType: "application/json",
                success: function (r) {
                    if (r.ok) {
                        window.location = "/courseMgr.html";
                    } else {
                        alert(r.msg)
                    }
                }
            });
        })
    })
</script>
</body>
</html>